/**
 * 
 */
package com.yullage.ann.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Yu-chun Huang
 * 
 */
public abstract class Neuron {

	private static int counter = 0;
	public final int id; // auto increment, starts at 0
	protected NeuronType type;

	protected double output;

	protected List<Connection> inConnections = new ArrayList<Connection>();
	protected Map<Integer, Connection> inConnectionLookup = new HashMap<Integer, Connection>();

	public Neuron() {
		id = counter;
		counter++;
	}

	public abstract void calculateOutput();

	public void addInNeuron(List<Neuron> neurons) {
		for (Neuron neuron : neurons) {
			addInNeuron(neuron);
		}
	}

	public void addInNeuron(Neuron neuron) {
		Connection con = new Connection(neuron, this);
		inConnections.add(con);
		inConnectionLookup.put(neuron.id, con);
	}

	public Connection getInConnection(int neuronIndex) {
		return inConnectionLookup.get(neuronIndex);
	}

	public List<Connection> getAllInConnections() {
		return inConnections;
	}

	public double getOutput() {
		return output;
	}

	public void setOutput(double o) {
		output = o;
	}

}
